<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="use clipboard directly" name="directly">
        <el-input v-model="inputData" placeholder="Please input" style="width:400px;max-width:100%;" />
        <el-button type="primary" :icon="Document" @click="handleCopy(inputData, $event)">
          copy
        </el-button>
      </el-tab-pane>
      <el-tab-pane label="use clipboard by v-directive" name="v-directive">
        <el-input v-model="inputData" placeholder="Please input" style="width:400px;max-width:100%;" />
        <el-button v-clipboard:copy="inputData" v-clipboard:success="clipboardSuccess" type="primary" :icon="Document">
          copy
        </el-button>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
export default {
  name: 'ClipboardDemo'
}
</script>
<script setup>
import {
  Document
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import clip from '@/utils/clipboard' // use clipboard directly
import clipboard from '@/directive/clipboard'

import { ref } from 'vue'

const activeName = ref('directly')
const inputData = ref('https://github.com/PanJiaChen/vue-element-admin')

const handleCopy = (text, event) => {
  clip(text, event)
}

const clipboardSuccess = () => {
  ElMessage({
    message: 'Copy successfully',
    type: 'success',
    duration: 1500
  })
}

const vClipboard = clipboard

</script>
<style scoped>

</style>
